package com.baizhi.controller;


import com.baizhi.dto.CategoryPageDTO;
import com.baizhi.dto.PageDTO;
import com.baizhi.entity.Category;
import com.baizhi.service.CategoryService;
import com.baizhi.vo.CommonQueryPageVo;
import com.baizhi.vo.CommonVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
public class CategoryController {

    private static final Logger log = LoggerFactory.getLogger(CategoryController.class);
    @Resource
    CategoryService categoryService;

    @RequestMapping("/category/queryOnePage")
    public CommonQueryPageVo queryOnePage(@RequestBody PageDTO pageDTO){

        log.info("接受的数据pageDTO：{}",pageDTO);

        return categoryService.queryOnePage(pageDTO);

    }

    @RequestMapping("/category/add")
    public CommonVo add(@RequestBody Category category){

        log.info("接受的数据category：{}",category);

        return categoryService.add(category);

    }


    @RequestMapping("/category/delete")
    public CommonVo delete(@RequestBody Category category){

        log.info("接受的数据category：{}",category);

        try {
            String delete = categoryService.deletes(category);
            return CommonVo.success(delete);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonVo.faild(e.getMessage());
        }

    }

    /*@RequestMapping("/category/delete")
    public CommonVo delete(@RequestBody Category category){

        log.info("接受的数据category：{}",category);

        return categoryService.delete(category);

    }*/

    @RequestMapping("/category/queryById")
    public Category queryById(String id){

        log.info("接受的数据id：{}",id);

        return categoryService.queryById(id);

    }

    @RequestMapping("/category/update")
    public CommonVo update(@RequestBody Category category){

        log.info("接受的数据id：{}",category);

        return categoryService.update(category);

    }

    @RequestMapping("/category/queryTwoPage")
    public CommonQueryPageVo update(@RequestBody CategoryPageDTO categoryPageDTO){

        log.info("接受的数据id：{}",categoryPageDTO);

        return categoryService.queryTwoPage(categoryPageDTO);

    }

    @RequestMapping("/category/queryByLevelsCategory")
    public List<Category> queryByLevelsCategory(Integer levels){

        log.info("接受的数据id：{}",levels);

        return categoryService.queryByLevelsCategory(levels);

    }


}
